import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DeviceQuery, DevicePageResult, DeviceForm, DeviceConfigForm } from "./types";

/**
 * 获取设备分页数据
 *
 * @param queryParams
 */
export function getDevicePage(
  queryParams?: DeviceQuery
): AxiosPromise<DevicePageResult> {
  return request({
    url: '/api/v1/device/page',
    method: 'get',
    params: queryParams
  });
}

/**
 * 获取设备下拉数据
 *
 * @param queryParams
 */
export function listDeviceOptions(
  queryParams?: DeviceQuery
): AxiosPromise<OptionType[]> {
  return request({
    url: '/api/v1/device/options',
    method: 'get',
    params: queryParams
  });
}

/**
 * 获取设备的菜单ID集合
 *
 * @param queryParams
 */
export function getDeviceMenuIds(roleId: number): AxiosPromise<number[]> {
  return request({
    url: '/api/v1/device/' + roleId + '/menuIds',
    method: 'get'
  });
}

/**
 * 获取设备详情
 *
 * @param id
 */
export function getDeviceForm(id: number): AxiosPromise<DeviceForm> {
  return request({
    url: '/api/v1/device/' + id + '/form',
    method: 'get'
  });
}



export function getDeviceConfigForm(id: number): AxiosPromise<DeviceForm> {
	return request({
		url: '/api/v1/device/config/' + id ,
		method: 'get'
	});
}

/**
 * 添加设备
 *
 * @param data
 */
export function addDevice(data: DeviceForm) {
  return request({
    url: '/api/v1/device/add',
    method: 'post',
    data: data
  });
}

/**
 * 更新设备
 *
 * @param id
 * @param data
 */
export function updateDevice(id: number, data: DeviceForm) {
  return request({
    url: '/api/v1/device/update/' + id,
    method: 'post',
    data: data
  });
}
export function updateDeviceConfig(deviceId: number, data: DeviceConfigForm) {
	return request({
		url: '/api/v1/device/updateConfig/' + deviceId,
		method: 'post',
		data: data
	});
}

export function deleteDeviceById(deviceId: number) {
  return request({
    url: '/api/v1/device/delete?deviceId=' +deviceId ,
    method: 'get'
  });
}


/**
 * 批量删除设备，多个以英文逗号(,)分割
 *
 * @param ids
 */
export function deleteDevices(ids: string) {
  return request({
    url: '/api/v1/device/' + ids,
    method: 'delete'
  });
}
